package com.ucode.cgms.job;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

/**
 * 系统自动取消超时未支付订单定时任务
 * @Author: liliang
 * @Date: 2023/3/7 23:55
 * @Version: 1.0
 */
@Component
public class CgmsOrderAutoCancelJob {

    private static Log log = LogFactory.get();

    //@Resource
    //private EcmsOrderService ecmsOrderService;

    /**
     * 订单自动取消任务
     */
    @XxlJob("CompanionOrderAutoCancelJobHandler")
    public void orderAutoCancelJobHandler() throws Exception{
        ////任务参数
        //String param = XxlJobHelper.getJobParam();
        //
        //log.debug("【订单自动取消任务】任务开始执行...,任务参数:{}",param);
        //XxlJobHelper.log("任务开始执行...,任务参数:{}",param);
        //Date endExpireTime = new Date();
        //Long maxMasterOrderNo = null;
        //Integer count = 100;
        //Boolean isnext = true;
        //int orderSize = 0;
        //while (isnext) {
        //    List<Long> masterOrderNoList = ecmsOrderService.queryPageForMasterOrderNoListByPayExpire(endExpireTime,maxMasterOrderNo,count);
        //    if(CollUtil.isNotEmpty(masterOrderNoList)){
        //        for(Long masterOrderNo : masterOrderNoList){
        //            try {
        //                Set<Long> orderIds = ecmsOrderService.cancelByMasterOrderNo(masterOrderNo, EcmsOrderCancelTypeEnum.PAY_TIMEOUT);
        //                orderSize = orderSize + orderIds.size();
        //            }catch (Exception e) {
        //
        //            }
        //        }
        //    }
        //
        //    if(CollUtil.isEmpty(masterOrderNoList) || masterOrderNoList.size() < count){
        //        isnext = false;
        //    }
        //}
        //XxlJobHelper.log("共取消未支付订单数量:{}",orderSize);
        //log.debug("【订单自动取消任务】任务执行完成...");
        //XxlJobHelper.log("任务执行完成...");
    }

}
